****
****	individual_script.do
****
****
****	Replication file for
****
****	"Health and Voting in Rural America"
****
****	Katie Cahill and Christopher Ojeda
****
****	Frontiers in Political Science (2021)
****


use "individual_data.dta", clear

**
** Figure 4
tab srhi3 vote_elections_num, row

gen tile_turnout = .
replace tile_turnout = 64.71 if _n == 1 
replace tile_turnout = 50.00 if _n == 2
replace tile_turnout = 41.67 if _n == 3
replace tile_turnout = 10.92 if _n == 4
replace tile_turnout = 23.28 if _n == 5
replace tile_turnout = 14.81 if _n == 6 
replace tile_turnout = 5.88 if _n == 7 
replace tile_turnout = 10.34 if _n == 8
replace tile_turnout = 11.11 if _n == 9
replace tile_turnout = 18.49 if _n == 10
replace tile_turnout = 16.38 if _n == 11
replace tile_turnout = 32.41 if _n == 12

 forvalues i=1(1)12{
gen tile_turnout`i' = .
replace tile_turnout`i' = tile_turnout if _n == `i'
}
*

gen n_var = .
replace n_var=1 if _n==1
replace n_var=2 if _n==2
replace n_var=3 if _n==3
replace n_var=5 if _n==4
replace n_var=6 if _n==5
replace n_var=7 if _n==6
replace n_var=9 if _n==7
replace n_var=10 if _n==8
replace n_var=11 if _n==9
replace n_var=13 if _n==10
replace n_var=14 if _n==11
replace n_var=15 if _n==12

graph twoway (bar tile_turnout1 n_var, fcolor(white) lcolor(black) lwidth(thin)) ///
	(bar tile_turnout2 n_var, fcolor(gs12) lcolor(black) lwidth(thin)) ///
	(bar tile_turnout3 n_var, fcolor(black) lcolor(black) lwidth(thin)) ///
	(bar tile_turnout4 n_var, fcolor(white) lcolor(black) lwidth(thin)) ///
	(bar tile_turnout5 n_var, fcolor(gs12) lcolor(black) lwidth(thin)) ///
	(bar tile_turnout6 n_var, fcolor(black) lcolor(black) lwidth(thin)) ///
	(bar tile_turnout7 n_var, fcolor(white) lcolor(black) lwidth(thin)) ///	
	(bar tile_turnout8 n_var, fcolor(gs12) lcolor(black) lwidth(thin)) ///
	(bar tile_turnout9 n_var, fcolor(black) lcolor(black) lwidth(thin)) ///	
	(bar tile_turnout10 n_var, fcolor(white) lcolor(black) lwidth(thin)) ///
	(bar tile_turnout11 n_var, fcolor(gs12) lcolor(black) lwidth(thin)) ///
	(bar tile_turnout12 n_var, fcolor(black) lcolor(black) lwidth(thin)), ///
	legend(order(1 2 3) label(1 "Poor/Fair" "Health") label(2 "Good" "Health") label(3 "Very Good/" "Excellent Health") row(1) size(small)) ///
	ytitle("Percentage Reporting") ///
	ylabel(0 10 20 30 40 50 60 70 80 90 100, labsize(2.5) angle(horizontal) nogrid) ///
	yline(0 10 20 30 40 50 60 70 80 90 100, lcolor(gs8)) ///
	xlabel(2 "Hardly Ever Votes" 6 "Sometimes Votes" 10 "Often Votes" 14 "Always Votes", labsize(2.5)) ///
	xtitle(" ") ///
	yscale(titlegap(2)) ///
	scheme(s1mono) graphregion(fcolor(white)) ///
	name(bivariate_survey, replace)

	
	
**
** Table 8

* Model 11
ologit vote_elections_num selfratehealth_num ageyears_num female highschoolorless householdincome_num, robust

* Model 12
ologit vote_elections_num selfratehealth_num ageyears_num female highschoolorless householdincome_num religious_num, robust

* Model 13
logit voteelection_binaryweak selfratehealth_num ageyears_num female highschoolorless householdincome_num religious_num, robust

* Model 14
logit voteelection_binary selfratehealth_num ageyears_num female highschoolorless householdincome_num religious_num, robust

* Model 15
logit voteelection_binarystrong selfratehealth_num ageyears_num female highschoolorless householdincome_num religious_num, robust




**
** Figure 5

logit voteelection_binaryweak selfratehealth_num ageyears_num female highschoolorless householdincome_num religious_num, robust
margins, at(selfratehealth_num=(1 2 3 4 5)) atmean
matrix B = r(table)'
svmat B, name(weak_est)

logit voteelection_binary selfratehealth_num ageyears_num female highschoolorless householdincome_num religious_num, robust
margins, at(selfratehealth_num=(1 2 3 4 5)) atmean
matrix B = r(table)'
svmat B, name(mod_est)

logit voteelection_binarystrong selfratehealth_num ageyears_num female highschoolorless householdincome_num religious_num, robust
margins, at(selfratehealth_num=(1 2 3 4 5)) atmean
matrix B = r(table)'
svmat B, name(strong_est)

gen seq1 = _n
replace seq1 = . if _n > 5

graph twoway (rspike weak_est5 weak_est6 seq1, lcolor(black)) ///
			(scatter weak_est1 seq1, mfcolor(white) mlcolor(black) msymbol(o)), ///
			legend(off) ///
			ytitle("Predicted Probability of Voting Sometimes, Often, or Always") ///
			ylabel(0 .1 .2 .3 .4 .5 .6 .7 .8 .9 1.0, labsize(2.5) angle(horizontal) nogrid) ///
			yline(0 .1 .2 .3 .4 .5 .6 .7 .8 .9 1.0, lcolor(gs8)) ///
			xlabel(1 `""Poor" "Health""' 2 `""Fair" "Health""' 3 `""Good" "Health""' 4 `""Very Good" "Health""' 5 `""Excellent" "Health""', labsize(2)) ///
			xtitle(" ") ///
			title("Model 13:" "Weak Turnout") ///
			yscale(titlegap(1)) ///
			scheme(s1mono) graphregion(fcolor(white)) ///
			name(weak_turnout, replace)

graph twoway (rspike mod_est5 mod_est6 seq1, lcolor(black)) ///
			(scatter mod_est1 seq1, mfcolor(white) mlcolor(black) msymbol(o)), ///
			legend(off) ///
			ytitle("Predicted Probability of Voting Often or Always") ///
			ylabel(0 .1 .2 .3 .4 .5 .6 .7 .8 .9 1.0, labsize(2.5) angle(horizontal) nogrid) ///
			yline(0 .1 .2 .3 .4 .5 .6 .7 .8 .9 1.0, lcolor(gs8)) ///
			xlabel(1 `""Poor" "Health""' 2 `""Fair" "Health""' 3 `""Good" "Health""' 4 `""Very Good" "Health""' 5 `""Excellent" "Health""', labsize(2)) ///
			xtitle(" ") ///
			title("Model 14:" "Moderate Turnout") ///
			yscale(titlegap(1)) ///
			scheme(s1mono) graphregion(fcolor(white)) ///
			name(mod_turnout, replace)

graph twoway (rspike strong_est5 strong_est6 seq1, lcolor(black)) ///
			(scatter strong_est1 seq1, mfcolor(white) mlcolor(black) msymbol(o)), ///
			legend(off) ///
			ytitle("Predicted Probability of Voting Always") ///
			ylabel(0 .1 .2 .3 .4 .5 .6 .7 .8 .9 1.0, labsize(2.5) angle(horizontal) nogrid) ///
			yline(0 .1 .2 .3 .4 .5 .6 .7 .8 .9 1.0, lcolor(gs8)) ///
			xlabel(1 `""Poor" "Health""' 2 `""Fair" "Health""' 3 `""Good" "Health""' 4 `""Very Good" "Health""' 5 `""Excellent" "Health""', labsize(2)) ///
			xtitle(" ") ///
			title("Model 15:" "Strong Turnout") ///
			yscale(titlegap(1)) ///
			scheme(s1mono) graphregion(fcolor(white)) ///
			name(strong_turnout, replace)

graph combine weak_turnout mod_turnout strong_turnout, ycommon row(1) graphregion(fcolor(white))



**
** Figure 6
logit voteelection_binaryweak selfratehealth_num ageyears_num female highschoolorless householdincome_num religious_num, robust
margins, at(selfratehealth_num=(1 2 3 4 5) female=(1) highschoolorless=(1)) atmean
margins, at(selfratehealth_num=(1 2 3 4 5) female=(0) highschoolorless=(1)) atmean
margins, at(selfratehealth_num=(1 2 3 4 5) female=(1) highschoolorless=(0)) atmean
margins, at(selfratehealth_num=(1 2 3 4 5) female=(0) highschoolorless=(0)) atmean

gen pred_turnout = .
replace pred_turnout = .292 if _n == 1
replace pred_turnout = .371 if _n == 2
replace pred_turnout = .461 if _n == 3  
replace pred_turnout = .552 if _n == 4
replace pred_turnout = .639 if _n == 5

replace pred_turnout = .249 if _n == 6
replace pred_turnout = .320 if _n == 7
replace pred_turnout = .402 if _n == 8
replace pred_turnout = .492 if _n == 9
replace pred_turnout = .581 if _n == 10

replace pred_turnout = .492 if _n == 11
replace pred_turnout = .582 if _n == 12
replace pred_turnout = .667 if _n == 13
replace pred_turnout = .741 if _n == 14
replace pred_turnout = .801 if _n == 15

replace pred_turnout = .436 if _n == 16
replace pred_turnout = .524 if _n == 17
replace pred_turnout = .611 if _n == 18
replace pred_turnout = .691 if _n == 19
replace pred_turnout = .759 if _n == 20

gen pred_turnout_lb = .
replace pred_turnout_lb = .189 if _n == 1
replace pred_turnout_lb = .313 if _n == 2
replace pred_turnout_lb = .456 if _n == 3  
replace pred_turnout_lb = .482 if _n == 4
replace pred_turnout_lb = .507 if _n == 5

replace pred_turnout_lb = .160 if _n == 6
replace pred_turnout_lb = .267 if _n == 7
replace pred_turnout_lb = .400 if _n == 8
replace pred_turnout_lb = .419 if _n == 9
replace pred_turnout_lb = .439 if _n == 10

replace pred_turnout_lb = .369 if _n == 11
replace pred_turnout_lb = .523 if _n == 12
replace pred_turnout_lb = .665 if _n == 13
replace pred_turnout_lb = .683 if _n == 14
replace pred_turnout_lb = .701 if _n == 15

replace pred_turnout_lb = .321 if _n == 16
replace pred_turnout_lb = .466 if _n == 17
replace pred_turnout_lb = .609 if _n == 18
replace pred_turnout_lb = .633 if _n == 19
replace pred_turnout_lb = .656 if _n == 20

gen pred_turnout_ub = .
replace pred_turnout_ub = .411 if _n == 1
replace pred_turnout_ub = .434 if _n == 2
replace pred_turnout_ub = .463 if _n == 3  
replace pred_turnout_ub = .618 if _n == 4
replace pred_turnout_ub = .754 if _n == 5

replace pred_turnout_ub = .361 if _n == 6
replace pred_turnout_ub = .380 if _n == 7
replace pred_turnout_ub = .405 if _n == 8
replace pred_turnout_ub = .557 if _n == 9
replace pred_turnout_ub = .701 if _n == 10

replace pred_turnout_ub = .626 if _n == 11
replace pred_turnout_ub = .622 if _n == 12
replace pred_turnout_ub = .669 if _n == 13
replace pred_turnout_ub = .792 if _n == 14
replace pred_turnout_ub = .886 if _n == 15

replace pred_turnout_ub = .560 if _n == 16
replace pred_turnout_ub = .585 if _n == 17
replace pred_turnout_ub = .614 if _n == 18
replace pred_turnout_ub = .750 if _n == 19
replace pred_turnout_ub = .856 if _n == 20


 forvalues i=1(1)20{
gen pred_turnout`i' = .
replace pred_turnout`i' = pred_turnout if _n == `i'
}
*

drop n_var
gen n_var = .
replace n_var=1 if _n==1
replace n_var=2 if _n==6
replace n_var=3 if _n==11
replace n_var=4 if _n==16

replace n_var=6 if _n==2
replace n_var=7 if _n==7
replace n_var=8 if _n==12
replace n_var=9 if _n==17

replace n_var=11 if _n==3
replace n_var=12 if _n==8
replace n_var=13 if _n==13
replace n_var=14 if _n==18

replace n_var=16 if _n==4
replace n_var=17 if _n==9
replace n_var=18 if _n==14
replace n_var=19 if _n==19

replace n_var=21 if _n==5
replace n_var=22 if _n==10
replace n_var=23 if _n==15
replace n_var=24 if _n==20

gen percent_str = "."
replace percent_str = "67%" if _n == 1
replace percent_str = "61%" if _n == 2
replace percent_str = "58%" if _n == 3
replace percent_str = "56%" if _n == 4
replace percent_str = "51%" if _n == 5
replace percent_str = "66%" if _n == 6
replace percent_str = "61%" if _n == 7
replace percent_str = "59%" if _n == 8
replace percent_str = "57%" if _n == 9
replace percent_str = "52%" if _n == 10

graph twoway (bar pred_turnout1 n_var, fcolor(white) lcolor(black) lwidth(thin)) ///
	(bar pred_turnout2 n_var, fcolor(white) lcolor(black) lwidth(thin)) ///
	(bar pred_turnout3 n_var, fcolor(white) lcolor(black) lwidth(thin)) ///
	(bar pred_turnout4 n_var, fcolor(white) lcolor(black) lwidth(thin)) ///
	(bar pred_turnout5 n_var, fcolor(white) lcolor(black) lwidth(thin)) ///
	(bar pred_turnout6 n_var, fcolor("189 189 189") lcolor(black) lwidth(thin)) ///
	(bar pred_turnout7 n_var, fcolor("189 189 189") lcolor(black) lwidth(thin)) ///	
	(bar pred_turnout8 n_var, fcolor("189 189 189") lcolor(black) lwidth(thin)) ///
	(bar pred_turnout9 n_var, fcolor("189 189 189") lcolor(black) lwidth(thin)) ///
	(bar pred_turnout10 n_var, fcolor("189 189 189") lcolor(black) lwidth(thin)) ///
	(bar pred_turnout11 n_var, fcolor("82 82 82") lcolor(black) lwidth(thin)) ///
	(bar pred_turnout12 n_var, fcolor("82 82 82") lcolor(black) lwidth(thin)) ///
	(bar pred_turnout13 n_var, fcolor("82 82 82") lcolor(black) lwidth(thin)) ///
	(bar pred_turnout14 n_var, fcolor("82 82 82") lcolor(black) lwidth(thin)) ///
	(bar pred_turnout15 n_var, fcolor("82 82 82") lcolor(black) lwidth(thin)) ///
	(bar pred_turnout16 n_var, fcolor(black) lcolor(black) lwidth(thin)) ///
	(bar pred_turnout17 n_var, fcolor(black) lcolor(black) lwidth(thin)) ///
	(bar pred_turnout18 n_var, fcolor(black) lcolor(black) lwidth(thin)) ///
	(bar pred_turnout19 n_var, fcolor(black) lcolor(black) lwidth(thin)) ///
	(bar pred_turnout20 n_var, fcolor(black) lcolor(black) lwidth(thin)) ///
	(rspike pred_turnout_lb pred_turnout_ub n_var, lcolor(black)), ///
	legend(order(1 6 11 16) label(1 "Women/HS or Less") label(6 "Men/HS or Less") label(11 "Women/More than HS") label(16 "Men/More than HS")) ///
	ytitle("Probability of Weak Turnout") ///
	ylabel(0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1.0, labsize(2.5) angle(horizontal) nogrid) ///
	yline(0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1.0, lcolor(gs8)) ///
	xlabel(2.5 "Poor Health" 7.5 "Fair Health" 12.5 "Good Health" 17.5 "Very Good Health" 22.5 "Excellent Health", labsize(2.5)) ///
	xtitle(" ") ///
	yscale(titlegap(2)) ///
	xscale(titlegap(2)) ///
	scheme(s1mono) graphregion(fcolor(white)) ///
	name(demo_pred, replace)
